<?php

namespace App\Admin\Controllers;

use App\Models\Apply;
use App\Models\Visitor;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Encore\Admin\Widgets\Box;

class VisitorsController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '访客列表';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Visitor());
        $grid->model()->orderByDesc('id');

        $grid->column('id', __('ID'));
        $grid->column('ip', __('IP地址'));
        $grid->column('froms', __('来源'));
        $grid->column('system', __('系统'));
        $grid->column('browser', __('浏览器'));
        $grid->column('created_at', __('创建时间'));

        $grid->disableCreateButton();
        $grid->disableFilter();
        $grid->disableActions();
        $grid->disableExport();

        $grid->header(function ($query) {
            $total = $query->count();
            $totalTotal = $query->whereDate('created_at',date('Y-m-d') )->count();
            $text = sprintf("总访问量 【 %s 】， 今天访问量【 %u 】 ", $total, $totalTotal);
            return new Box('访问量', $text);

        });
        $grid->export(function ($export) {

        });

        return $grid;
    }


}
